unit scDateShift;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGridEh, StdCtrls, Buttons, sBitBtn, DBCtrls, sDBEdit,
  sTooledit, Mask, sMaskEdit, sCustomComboEdit, sDBDateEdit, DB, ExtCtrls,
  sBevel, sEdit, sLabel, sDBText, ActnList, DBActns;

type
  TfmDateShift = class(TForm)
    dbgRespSearch: TDBGridEh;
    sbtbtnOk: TsBitBtn;
    sbtbtnCacel: TsBitBtn;
    edtShiftTo: TsDateEdit;
    btnShift: TsBitBtn;
    btnUnShift: TsBitBtn;
    dsExpDate: TDataSource;
    sbvl1: TsBevel;
    dsSms: TDataSource;
    edtNote: TsEdit;
    edtdExp: TsDBDateEdit;
    actShift: TActionList;
    actDel: TDataSetDelete;
    procedure dsExpDateDataChange(Sender: TObject; Field: TField);
    procedure btnShiftClick(Sender: TObject);
    procedure btnUnShiftClick(Sender: TObject);
    procedure edtShiftToChange(Sender: TObject);
  private
    procedure shiftDate;
    procedure unShiftDate;
  public
    { Public declarations }
  end;

implementation

{$R *.dfm}

procedure TfmDateShift.dsExpDateDataChange(Sender: TObject; Field: TField);
begin
  btnUnShift.Enabled := dsExpDate.DataSet.RecordCount > 0;
end;

procedure TfmDateShift.btnShiftClick(Sender: TObject);
begin
  shiftDate;
end;

procedure TfmDateShift.shiftDate;
begin
  if (edtShiftTo.Date > 0) and (edtShiftTo.Date > edtdExp.Date) then
  begin
    dsExpDate.DataSet.Append;
    dsExpDate.DataSet.FieldByName('sms_id').AsInteger :=
        dsSms.DataSet.FieldByName('id').AsInteger;
    dsExpDate.DataSet.FieldByName('expdate').AsDateTime := edtdExp.Date;
    dsExpDate.DataSet.FieldByName('note').AsString := edtNote.Text;
    dsExpDate.DataSet.Post;
    dsSms.DataSet.Edit;
    edtdExp.Field.AsDateTime := edtShiftTo.Date;
    edtShiftTo.Date := 0;
    edtNote.Text := '';
  end;
end;

procedure TfmDateShift.unShiftDate;
begin
  dsSms.DataSet.Edit;
  edtdExp.Field.AsDateTime := dsExpDate.DataSet.FieldByName('expdate').AsDateTime;
  dsExpDate.DataSet.Delete;
end;

procedure TfmDateShift.btnUnShiftClick(Sender: TObject);
begin
  unShiftDate;
end;

procedure TfmDateShift.edtShiftToChange(Sender: TObject);
begin
  btnShift.Enabled := (edtShiftTo.Date > 0) and (edtShiftTo.Date > edtdExp.Date);
end;

end.
